// import 'package:alarm/alarm.dart';
import 'package:app_tracking_transparency/app_tracking_transparency.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:get/get_navigation/src/routes/transitions_type.dart';
import 'common/common_lib/val_data_base_manager.dart';
import 'common/config/val_client_url_path.dart';
import 'common/ui/val_auto_fit_screen_size.dart';
import 'common/util/val_app_state_tool.dart';
import 'common/util/val_logger_manager.dart';
import 'common/util/val_router_manager.dart';
import 'http/val_dio_fetch_kit.dart';

Future<void> main() async {

  WidgetsFlutterBinding.ensureInitialized();

  await _init();

  ValDioFetchKit.getInstance().setup(ValClientUrlPath.main);

  await ValDioFetchKit.getInstance().initHeaders();

  await ValAppStateTool.setup();

  final status = await AppTrackingTransparency.requestTrackingAuthorization();

  ValDataBaseManager().setup();

  // await Alarm.init();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return  GetMaterialApp(
      builder: FlutterSmartDialog.init(builder: (context, widget) {
        return MediaQuery(
          //设置文字大小不随系统设置改变
          data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
          child: widget!,
        );
      }),
      debugShowCheckedModeBanner: false,
      defaultTransition: Transition.cupertino,
      navigatorObservers: const [],
      title: '',
      localeListResolutionCallback: (deviceLocale, supportedLocales) {
        ValAppStateTool().currentLocale =  deviceLocale?.first.languageCode ?? '';
        ValLoggerManager.stat(page: ValConfigLoggerPath.launchPage);
      },
      home: ValRouterManager.getRoot(),
    );
  }
}

Future<void> _init() async {
  await ValAutoFitScreenSize().initialize(375, 667);
}
